const goodsModel = require("../../db/models")["goods"];
const responseCode = require("../../config/httpCode");
const { Op } = require("sequelize");
const router = require("koa-router")({
  prefix: "/auth/goods"
});

// 获取新书
router.get("/new", async ctx => {
  const books = await goodsModel.findAll({
    limit: 8,
    order: [["createdAt", "DESC"]]
  });
  ctx.body = {
    code: 200,
    data: books
  };
});

// 获取畅销书
router.get("/hot", async ctx => {
  const books = await goodsModel.findAll({
    limit: 10,
    order: [["view", "DESC"]]
  });
  ctx.body = {
    code: 200,
    data: books
  };
});

module.exports = router;
